﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Downplay.Gravity.Events;

namespace Downplay.Gravity.Drivers
{
    /// <summary>
    /// Data driver specifically for drop handling
    /// </summary>
    public abstract class DropZoneDriver : IDataDriver
    {
        public abstract IEnumerable<string> ForShapes();

        protected abstract string Identifier(ShapeDataContext context);

        public void ModifyDataValues(Events.ShapeDataContext context)
        {
            var dec = new ShapeDataDecoration(){
                DecorationMode = DataDecorationModes.AddDataWrapper
            };
            dec.Data["ZoneId"] = Identifier(context);
            dec.Data["ZoneType"] = context.ShapeType;
            OnModifyData(context, dec);
            context.Decorations.Add(dec);
        }

        protected abstract void OnModifyData(ShapeDataContext context, ShapeDataDecoration dec);

        public void Action(Filters.AjaxResult result, Models.GravityData data)
        {
            // Check we have appropriate data
            var dropData = data.TryGetModel<DropZoneData>();
            if (dropData == null) return;

            var handleData = data.TryGetModel<DragHandleData>();
            if (handleData == null) return;

            // TODO: Want to start handling other ajax scenarios; for instance simple clicks

            // Perform the drop
            OnDropped(result, data, dropData, handleData);
        }

        protected abstract void OnDropped(Filters.AjaxResult result, Models.GravityData data, DropZoneData dropData, DragHandleData handleData);

    }
}
